package com.cyc.controller;

import com.cyc.model.Information;
import com.cyc.model.User;
import com.cyc.service.InfomationService;
import com.cyc.tools.Layui;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


@Controller
@RequestMapping("/student")
public class StudentController {
    @Resource
    InfomationService infomationService;
    @RequestMapping("/")
    public String student(){
        return "student";
    }
    @RequestMapping("/getAll")
    @ResponseBody
    public Layui getAll(){
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        //获取当前登录的用户信息
        return infomationService.getOne(user.getUsername());
    }
    @RequestMapping("/edit")
    @ResponseBody
    public void edit(Information information){
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        //修改信息
        information.setUsername(user.getUsername());
        infomationService.addOrEditOne(information);
        getAll();
    }
}
